﻿/*
* 创建人:            @Model.Author
* 创建时间:          @Model.CreateTime
* 邮箱：             @Model.EmailAddress
* 文件功能描述：      @Model.FileRemark
*
* 修改人：
* 时间：
* 修改说明：
*/
@{
    Layout = null;
}

@using SJNScaffolding.Models.CollectiveType
@model SJNScaffolding.Models.TemplateModels.ViewFileModel
using System.Threading.Tasks;
using System.Web.Mvc;
using @(Model.ProjectName).Domain.Plat.@(Model.TableName)s;
using @(Model.ProjectName).Domain.Plat.@(Model.TableName)s.Dto;
using @(Model.ProjectName).Web.Controllers;
using @(Model.ProjectName).Domain.Common.Files;
namespace @(Model.ProjectName).Web.Areas.Plat.Controllers
{
    public class @(Model.TableName)Controller : @(Model.ProjectName)ControllerBase
    {
    #region 构造函数
    private readonly I@(Model.TableName)AppService _@(Model.TableNameCamel)AppService;
    @if (Model.WebUploadList.Count > 0)
    {@Html.Raw("        private readonly IAbpFileAppService _fileAppService;\r\n");
}
    public @(Model.TableName)Controller(I@(Model.TableName)AppService @(Model.TableNameCamel)AppService
    @if (Model.WebUploadList.Count > 0)
    {@Html.Raw("                            ,IAbpFileAppService fileAppService\r\n")}
    )
    {
    this._@(Model.TableNameCamel)AppService = @(Model.TableNameCamel)AppService;
    @if (Model.WebUploadList.Count > 0)
    {@Html.Raw("            this._fileAppService = fileAppService;\r\n")}
    }
    #endregion

    // GET: Plat/@(Model.TableName)

    #region 视图
    public ActionResult Index()
    {
    return View();
    }

    public ActionResult CreateOrUpdateModal()
    {
    return View();
    }

    #endregion

    #region 数据
    public async Task<@("ActionResult")>GetInfoForEdit(int id)
    {
        var output = await _@(Model.TableNameCamel)AppService.GetInfoForEdit(id);
        @if (Model.WebUploadList.Count > 0)
        {
            string webuploadParams = "";
            foreach (WebUploadColunm r in Model.WebUploadList)
            {
                webuploadParams += ",_fileAppService.GetFileOutput(output." + r.WebuploadId + ")";
            }
            @Html.Raw("            var " + Model.TableNameCamel + "ViewModel=new " + Model.TableName + "ViewModel(output" + webuploadParams + ");\r\n");
            @Html.Raw("            return Json(" + Model.TableNameCamel + "ViewModel" + ");\r\n");
        }
        else
        {
            @Html.Raw("            return Json(output);\r\n");
        }
    }

    public ActionResult GetGridByCondition(@(Model.TableName)SearchDto input)
    {
        var gridData = _@(Model.TableNameCamel)AppService.GetGridByCondition(input);
        return Json(gridData);
    }
    #endregion
    }
}
